﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using FlyHorse.LIMS.WinApp.Utils;
using DevExpress.Spreadsheet;

namespace FlyHorse.LIMS.WinApp.DataAnalyzeFroms.CurveForms
{
    public partial class ExportExcelForm : DevExpress.XtraEditors.XtraForm
    {
       
        //public ExportExcelForm(List<CurveData> dataList)
        //{
        //    InitializeComponent();
        //    //_dataList = dataList;
        //}

        public ExportExcelForm(DataSet dataSet)
        {
            InitializeComponent();
            InitExcelByTable( dataSet);
        }

        private void ExportExcelForm_Load(object sender, EventArgs e)
        {
            //InitExcelByTable(_dataList);
        }


        private void InitExcelByTable(DataSet dataSet)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheet = workbook.Worksheets[0];
            spreadsheetControl1.BeginUpdate();


            int a = 0;
            for (int j = 0; j < dataSet.Tables.Count; j++)
            {
                DataTable table = dataSet.Tables[j];
                worksheet[0, a + 1].Value = table.Namespace;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    worksheet[i+1, a].Value = table.Rows[i]["Argument"].ToString();
                    worksheet[i+1, a+1].Value = Convert.ToDouble(table.Rows[i]["Value"]);
                }
                a += 2;
            }
           
            spreadsheetControl1.EndUpdate();
        }



        private void InitExcelByList(List<CurveData> dataList)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheet = workbook.Worksheets[0];

            spreadsheetControl1.BeginUpdate();

            for (int i = 0; i < dataList.Count; i++)
            {
                worksheet[i, 0].Value = dataList[i].DataTime;
                worksheet[i, 1].Value = dataList[i].TestValue;
                if (dataList[i].samplingPlace != null)
                {
                    worksheet[i, 2].Value = dataList[i].samplingPlace.SamplingPlaceName;
                }
                if (dataList[i].customer != null)
                {
                    worksheet[i, 3].Value = dataList[i].customer.CustomerName;
                }
            }

            spreadsheetControl1.EndUpdate();
        }
    }
}